package com.food.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.food.bean.ShoppingUser;
import com.food.dao.UserDao;
import com.food.dto.UserDto;
import com.food.service.UserService;
import com.food.util.CommonUtil;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	@Override
	public boolean validate(UserDto userDto) {
		// TODO Auto-generated method stub
		if (userDto != null && !CommonUtil.isEmpty(userDto.getNickname())
				&& !CommonUtil.isEmpty(userDto.getPassword())) {

			ShoppingUser shoppingUser = new ShoppingUser();
			BeanUtils.copyProperties(userDto, shoppingUser);
			List<ShoppingUser> list = userDao.selectUser(shoppingUser);
			if (list.size() == 1) {
				BeanUtils.copyProperties(list.get(0), userDto);
				return true;
			}
			return false;
		}

		return false;
	}

}